package com.ruoyi.web.controller.byw;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BywProductResourcePack;
import com.ruoyi.system.service.IBywProductResourcePackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品Controller
 * 
 * @author ruoyi
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/byw/product-resource-pack")
public class BywProductResourcePackController extends BaseController
{
    @Autowired
    private IBywProductResourcePackService bywProductResourcePackService;

    /**
     * 查询产品列表
     */
    @PreAuthorize("@ss.hasPermi('byw:product-resource-pack:list')")
    @GetMapping("/list")
    public TableDataInfo list(BywProductResourcePack bywProductResourcePack)
    {
        startPage();
        bywProductResourcePack.setIsDelete(0);
        List<BywProductResourcePack> list = bywProductResourcePackService.selectBywProductResourcePackList(bywProductResourcePack);
        return getDataTable(list);
    }

    /**
     * 导出产品列表
     */
    @PreAuthorize("@ss.hasPermi('byw:product-resource-pack:export')")
    @Log(title = "产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BywProductResourcePack bywProductResourcePack)
    {
        List<BywProductResourcePack> list = bywProductResourcePackService.selectBywProductResourcePackList(bywProductResourcePack);
        ExcelUtil<BywProductResourcePack> util = new ExcelUtil<BywProductResourcePack>(BywProductResourcePack.class);
        util.exportExcel(response, list, "产品数据");
    }

    /**
     * 获取产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('byw:product-resource-pack:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bywProductResourcePackService.selectBywProductResourcePackById(id));
    }

    /**
     * 新增产品
     */
    @PreAuthorize("@ss.hasPermi('byw:product-resource-pack:add')")
    @Log(title = "产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BywProductResourcePack bywProductResourcePack)
    {
        bywProductResourcePack.setCreateBy(getUsername());
        bywProductResourcePack.setCreateTime(DateUtils.getNowDate());
        bywProductResourcePack.setUpdateBy(bywProductResourcePack.getCreateBy());
        bywProductResourcePack.setUpdateTime(bywProductResourcePack.getCreateTime());
        return toAjax(bywProductResourcePackService.insertBywProductResourcePack(bywProductResourcePack));
    }

    /**
     * 修改产品
     */
    @PreAuthorize("@ss.hasPermi('byw:product-resource-pack:edit')")
    @Log(title = "产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BywProductResourcePack bywProductResourcePack)
    {
        bywProductResourcePack.setUpdateBy(getUsername());
        bywProductResourcePack.setUpdateTime(DateUtils.getNowDate());
        return toAjax(bywProductResourcePackService.updateBywProductResourcePack(bywProductResourcePack));
    }

    /**
     * 删除产品
     */
    @PreAuthorize("@ss.hasPermi('byw:product-resource-pack:remove')")
    @Log(title = "产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        BywProductResourcePack bywProductResourcePack = bywProductResourcePackService.selectBywProductResourcePackById(id);
        if (bywProductResourcePack == null){
            return error("要删除的产品不存在");
        }
        bywProductResourcePack.setUpdateBy(getUsername());
        bywProductResourcePack.setUpdateTime(DateUtils.getNowDate());
        bywProductResourcePack.setIsDelete(1);
        return toAjax(bywProductResourcePackService.updateBywProductResourcePack(bywProductResourcePack));
    }
}
